/**
 * Created by Administrator on 2016/11/9.
 */
$.extend({
    change: function (obj) {
        var def = {
            transition: '0.5s linear',
            speed: 3000
        }
        if (obj.transition == "undefined") {
            obj.transition = def.transition
        }
        if (obj.speed == 'undefined') {
            obj.speed = def.speed
        }
        var i = 1;
        var stop;
        var length = $('.ppt-box').children().length;

        function change() {
            guodu();
            i++;
            if (i == length) {
                i = 0;
            }
        }

        $('.dot li').hover(function () {
            clearInterval(stop);
            i = $('.dot li').index($(this));
            guodu();
            i++;
            if (i == length) {
                i = 0;
            }
            stop = setInterval(change, obj.speed);
        })

        $('.next').click(function () {
            clearInterval(stop);
            guodu();
            i = i + 1;
            if (i == length) {
                i = 0;
            }
            stop = setInterval(change, obj.speed);
        })
        $('.prev').click(function () {
            clearInterval(stop);
            i = i - 1;
            if (i == -1) {
                i = length - 1;
            }
            guodu();
            stop = setInterval(change, obj.speed);
        })
        function guodu() {
            $('.ppt:eq(' + i + ')').css({'opacity': 1, 'transition': obj.transition})
            $('.ppt:eq(' + i + ')').siblings().css({'opacity': 0, 'transition': obj.transition});
            $('.dot li:eq(' + i + ')').css({
                background: 'url(pic/icon.png) no-repeat -50px -371px'
            }).siblings().css({
                background: 'url(pic/icon.png) no-repeat -50px -391px'
            })
        }

        stop = setInterval(change, obj.speed);
    }
})